"""
https://stackoverflow.com/questions/231767/what-does-the-yield-keyword-do
To master yield, you must understand that when you call the function, the code you have written in the function body
does not run. The function only returns the generator object, this is a bit tricky.

Then, your code will continue from where it left off each time for uses the generator.

Now the hard part:

The first time the for calls the generator object created from your function, it will run the code in your function
 from the beginning until it hits yield, then it'll return the first value of the loop. Then, each subsequent call will
  run another iteration of the loop you have written in the function and return the next value. This will continue
   until the generator is considered empty, which happens when the function runs without hitting yield. That can be
    because the loop has come to an end, or because you no longer satisfy an "if/else".
"""
import math
from PyCmpltrtok.common import sep

data_list = range(1, 101)


def get_data(batch_size):
    sep('get_data start')
    n_cycle = int(math.ceil(len(data_list) / batch_size))
    for i in range(n_cycle):
        yield data_list[i * batch_size:(i + 1) * batch_size]
    sep('get_data end')


for bd in get_data(32):
    print(bd)
